//
//  NBTabBarController.m
//  qiFenQi
//
//  Created by 戒了。 on 16/4/3.
//  Copyright © 2016年 xiaomage. All rights reserved.
//

#import "NBTabBarController.h"
#import "NBShoppingViewController.h"
#include "NBCheckViewController.h"
#import "NBDiscoverViewController.h"
#import "NBSellViewController.h"
#import "NBMeViewController.h"
#import "NBNavigationController.h"


@interface NBTabBarController ()

@end

@implementation NBTabBarController

+ (void)load
{
    
    // 获取当前类的tabBarItem
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    
    // 设置所有item的选中时颜色
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    // 文本颜色 -> 描述富文本属性的key -> NSAttributedString.h
    attr[NSForegroundColorAttributeName] = [UIColor redColor];
    [item setTitleTextAttributes:attr forState:UIControlStateSelected];
    
    // 通过normal状态设置字体大小
    NSMutableDictionary *attrnor = [NSMutableDictionary dictionary];
    attrnor[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    
    [item setTitleTextAttributes:attrnor forState:UIControlStateNormal];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 添加所有子控制器
    [self setupAllChildViewController];
    
    // 设置tabBar上对应按钮内容
    [self setupAllTileButton];

    
}

// 添加子控制器
- (void)setupAllChildViewController {
    
    // 添加子控制器
    // 购物
    NBShoppingViewController *shoppingVc = [[NBShoppingViewController alloc] init];
    shoppingVc.view.backgroundColor = NBRandomColor;
    
    NBNavigationController *nav = [[NBNavigationController alloc] initWithRootViewController:shoppingVc];
    [self addChildViewController:nav];
    
    // 白条
    NBCheckViewController *checkVc = [[NBCheckViewController alloc] init];
    checkVc.view.backgroundColor = NBRandomColor;
    
    NBNavigationController *nav1 = [[NBNavigationController alloc] initWithRootViewController:checkVc];
    [self addChildViewController:nav1];
    
    // 发现
    NBDiscoverViewController *discoverVc = [[NBDiscoverViewController alloc] init];
    discoverVc.view.backgroundColor = NBRandomColor;
    NBNavigationController *nav2 = [[NBNavigationController alloc] initWithRootViewController:discoverVc];
    [self addChildViewController:nav2];
    
    // 特卖
    NBSellViewController *sellVc = [[NBSellViewController alloc] init];
    sellVc.view.backgroundColor = NBRandomColor;
    NBNavigationController *nav3 = [[NBNavigationController alloc] initWithRootViewController:sellVc];
    
    [self addChildViewController:nav3];
    
    // 我的
    //通过storyboard加载
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"NBMeViewController" bundle:nil];
    NBMeViewController *meVc = [storyBoard instantiateInitialViewController];
    
    meVc.view.backgroundColor = [UIColor whiteColor];
    NBNavigationController *nav4 = [[NBNavigationController alloc] initWithRootViewController:meVc];
    [self addChildViewController:nav4];
    
}



#pragma mark - 设置所有标题按钮内容
- (void)setupAllTileButton
{
    // 0:购物
    UINavigationController *nav = self.childViewControllers[0];
    nav.tabBarItem.title = @"购物";
    nav.tabBarItem.image = [UIImage imageNamed:@"tab_si_shop"];
    nav.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"tab_si_shop_touchdown"];
    
    // 1:白条
    UINavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.title = @"白条";
    nav1.tabBarItem.image = [UIImage imageNamed:@"home_baitiao"];
    nav1.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"home_baitiao_touchdown"];
    
    // 2:发现
    UINavigationController *nav2 = self.childViewControllers[2];
    nav2.tabBarItem.title = @"发现";
    nav2.tabBarItem.image = [UIImage imageNamed:@"help"];
    nav2.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"help_pressed"];
    
    // 3:特卖
    UINavigationController *nav3 = self.childViewControllers[3];
    nav3.tabBarItem.title = @"特卖";
    nav3.tabBarItem.image = [UIImage imageNamed:@"home_temai"];
    nav3.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"discount_down"];
    
    // 4:我的
    UINavigationController *nav4 = self.childViewControllers[4];
    nav4.tabBarItem.title = @"我的";
    nav4.tabBarItem.image = [UIImage imageNamed:@"tab_si_me"];
    nav4.tabBarItem.selectedImage = [UIImage imageNameWithOriginal:@"tab_si_me_touchdown"];
    
}


@end
